import Cookies from "js-cookie";
import { getLoaclData } from "./public";

const TokenKey = 'loginToken'

export const getToken = () => {
    return Cookies.get(TokenKey)
}

export const setToken = (token) => {
    return Cookies.set(TokenKey, token)
}

export const removeToken = () => {
    return Cookies.remove(TokenKey)
}

export const expiredToken = () => {
    let nowTime = parseInt(Date.now() / 1000); //当前时间
    let expired_at = getLoaclData('expired_at'); //过期时间
    if(!expired_at) {
        removeToken();
    }else {
        if(+expired_at <= +nowTime) { // 已经过期
            removeToken();
        }
    }
}